﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace MusicPlayerPlus.Core.Reflection
{
    /// <summary>
    /// 反射接口的基类
    /// </summary>
    /// <typeparam name="T">接口类型</typeparam>
    /// <typeparam name="APT">给予实例动作的参数类型</typeparam>
    public class RAPBase<T, APT> : ReflectionBase<T> where APT : class, new()
    {
        #region 属性

        private APT acitonParam = null;
        /// <summary>
        /// AcitonParam
        /// </summary>
        public APT AcitonParam
        {
            get
            {
                if (acitonParam == null)
                {
                    acitonParam = MusicPlayerPlus.Core.Reflection.ActionParam.ActionData.GetActionParam<APT>(this.GetType());
                }
                return acitonParam;
            }
            set { acitonParam = value; }
        }

        #endregion

        /// <summary>
        /// 实例化继承该接口的所有方法
        /// </summary>
        /// <param name="item"></param>
        /// <param name="obj"></param>
        public virtual void Execute(Type item, object obj)
        {
            if (IsSucceed(item))
            {
                if (AddExtTypeItem(item))
                {
                    Instantiation(item, obj);
                }
            }
        }
        /// <summary>
        /// 实例化继承该接口的所有方法
        /// </summary>
        /// <param name="item"></param>
        /// <param name="obj"></param>
        protected virtual void Instantiation(Type classType, object obj)
        {

        }
    }
}
